<?
    class Functions {
        private static $_title = '';
        
        static function PrintHeader($title) {
            self::$_title = $title;
            if (Conf::$PrintedHeader) return;
        ?>
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
        <head>
            <title><?=SettingManager::GetSetting("Application Title")?> &raquo; <?=$title?></title>
            <?
                foreach (ThemeManager::GetStylesheets() as $css) {
                    echo "<link rel='stylesheet' type='text/css' href='$css' />\n";
                }
                foreach (scandir("js") as $js) {
                    if ($js[0] == '.' || !is_file("js/$js")) continue;
                    echo "<script type='text/javascript' language='javascript' src='js/$js'></script>\n";
                }
                
                if (SettingManager::GetSetting("Debug Enabled")) {
                    $debug = new SettingManager("Debug");
                    if ($debug->resize_window && $debug->window_width && $debug->window_height)
                        echo "<script type='text/javascript'>window.resizeTo({$debug->window_width},{$debug->window_height})</script>";
                }
            ?>
            <script type='text/javascript' language="javascript" src='js/scriptaculous/scriptaculous.js'></script>
            <script type='text/javascript' language="javascript" src='js/scriptaculous/effects.js'></script>
        </head>
        <body>
            <div id='container'>
                <div id='header' class='contentblock'>
                    <div style='float:left; width:75px;'><a href='index.php'><img style="border:none" border="0" src='<?=ThemeManager::GetImage("Crest")?>' /></a></div>
                    <div style='float:left; font-size:20pt;'>
                        <?=SettingManager::GetSetting("Application Title")?><br />
                        <span style='font-size:10pt;'><?=$title?></span>
                    </div>
                    <div style='float:right; width:250px; text-align:right; font-size: 8pt;'>
                        <div style='position:relative; float:left; width:49px; border-right:solid 1px white;'>
                            <img src='<?
                                if (AuthManager::AuthLevelMatches(AuthConstants::LANDLORDS)) {
                                    echo ThemeManager::GetImage("landlord_icon");
                                }
                                else if (AuthManager::AuthLevelMatches(AuthConstants::ADMINISTRATORS)) {
                                    echo ThemeManager::GetImage("admin_icon");
                                }
                                else if (AuthManager::AuthLevelMatches(array(AuthConstants::STUDENTS,AuthConstants::GUESTS))) {
                                    echo ThemeManager::GetImage("student_icon");
                                }
                                else {
                                    echo ThemeManager::GetImage("notloggedin_icon");
                                }
                            ?>' />
                        </div>
                        <div style='position:relative; float:right;'>
                            <div style='border-bottom:solid 1px white; padding:2px; width:190px; text-align:center; font-size:8pt;'><?=date("M d, Y g:i A")?></div>
                            <?
                                if (AuthManager::AuthLevelMatches(AuthConstants::ALL_LOGGED_IN)) {
                                    echo DBM::FetchOne("SELECT name FROM guests WHERE id=" . AuthManager::GetUserID() . ";") . "<br>";
                                    echo "<a style='color:#CCCCCC;' href='logout.php'>Logout</a>";
                                }
                                else echo "<a style='color:#CCCCCC;' href='login.php'>Guest/Landlord Login</a><br /><a style='color:#CCCCCC;' href='login.php?method=cas'>Student Login</a>";
                            ?>
                        </div>
                    </div>
                </div>
                <div id='menu' class='contentblock'><?=MenuManager::GetMainMenu()?></div>
                <div id='wrapper'>
                    <div id='content' class='contentblock'>
                    <?
                    
                    // print any pending messages
                    //if ($_SESSION['messages'] && count($_SESSION['messages']) > 0)
                    //    foreach ($_SESSION['messages'] as $message) echo $message;
                    
                    
            Conf::$PrintedHeader = true;    // set a flag so when there's errors we know if we need to print the header
        }
        
        static function PrintFooter() {
        ?>
                    </div>
                </div>
                <div id='navigation' class='contentblock'>
                    <?=MenuManager::RenderMenu(self::$_title)?>
                    <? 
                    if (MessageManager::HasMessages()) {
                    ?>
                    <span class='section_header'>Important Messages</span>
                    <span class='section_content'>
                        <? MessageManager::DisplayMessages(); ?>
                    </span>
                    <? 
                    }
                    
                    if ($_SESSION['recent'] && count($_SESSION['recent']) > 0) {
                    ?>
                    <span class='section_header'>Recently Looked At</span>
                    <span class='section_content'>
                        <ul class='minimal_padding'>
                            <? /* Iterate through $_SESSION['recent'] */ ?>
                            <li><a href='listing.php?id=1'>1234 Fake St.<br>
                                Somewhere, NY 12180</a></li>
                            <li><a href='listing.php?id=1'>4829 Imaginary Lane<br>
                                Nowhere, MI 48306</a></li>
                        </ul>
                    </span>
                    <? } ?>
                </div>
        <div id="footer" class='contentblock'> 
                <div id='footershadow'>&nbsp;</div>
            <div id="footer_padding"> 
                <br />
                <div class="footer-cell"> 
                    <h3><a href="http://home.union.rpi.edu/landings/view/1">Clubs</a></h3> 
                    <ul> 
                        <li><a href="http://home.union.rpi.edu/ZK-union/pages/view/4">Advertising &amp; Promotions</a></li> 
                        <li><a href="http://home.union.rpi.edu/ZK-union/pages/view/12">Starting a Club</a></li> 
                    </ul> 
                    <br /> 
                    <h3><a href="http://home.union.rpi.edu/pages/view/3">Finances</a></h3> 
                    <ul> 
                        <li><a href="http://annualreport.myrpi.org">Union Annual Report 2008</a></li> 
                    </ul> 
    
                </div> 
                <div class="footer-cell"> 
                    <h3><a href="http://home.union.rpi.edu/landings/view/3">Inside the Building</a></h3> 
                    <ul> 
                        <li><a href="http://home.union.rpi.edu/ZK-union/pages/view/12">About the Union</a></li> 
                        <li><a href="http://studentsenate.rpi.edu">Student Senate</a></li> 
                        <li><a href="http://bookstore.rpi.edu">Union Bookstore</a></li> 
                        <li><a href="http://home.union.rpi.edu/ZK-union/pages/view/8">Clubhouse Pub</a></li> 
                        <li><a href="http://home.union.rpi.edu/ZK-union/pages/view/10">Games Room</a></li> 
                        <li><a href="http://home.union.rpi.edu/ZK-union/pages/view/14">Campus Unisex</a></li> 
                        <li><a href="http://home.union.rpi.edu/ZK-union/pages/view/9">Legal Services</a></li> 
                        <li><a href="http://home.union.rpi.edu/ZK-union/pages/view/13">Bank</a></li> 
                    </ul> 
                </div> 
                <div class="footer-cell"> 
                    <h3><a href="http://home.union.rpi.edu/landings/view/4">Campus and Beyond</a></h3> 
                    <ul> 
                        <li><a href="http://rpinfo.rpi.edu">RPInfo</a></li> 
                        <li><a href="http://signage.rpi.edu">Concerto</a></li> 
                        <li><a href="http://housing.union.rpi.edu">Off-Campus Housing</a></li> 
                        <li><a href="http://myrpi.org/hosting">myRPI Hosting</a></li> 
                        <li><a href="http://rpiathletics.com">Athletics</a></li> 
                        <li><a href="http://www.muellercenter.rpi.edu/">Mueller Center</a></li> 
                        <li><a href="http://shuttles.rpi.edu">Shuttle Tracking</a></li> 
                        <li><a href="http://archer.union.rpi.edu">Archer Center</a></li> 
                        <li><a href="http://troyny.gov">City of Troy</a></li> 
                    </ul> 
                </div> 
                <div class="footer-cell" style="width:28%;"> 
                    <h3>Any Questions or Comments?</h3>
                    <p>How well does the Union provide for your time at RPI?  What can we do better?  Stop by the Union Admin Office on the third floor of the Rensselaer Union (Room 3702).</p> 
                    <h3>Republishing Content</h3> 
                    <p>For information about republishing material found within this website, or within the realm of the Union Web Services in general, please send an e-mail to <a href="mailto:webmaster@union.rpi.edu">webmaster@union.rpi.edu</a>. Photo credits are given where appropriate.</p> 
                </div> 
                <div style="clear:both;"></div> 
            <div id="subfooter"> 
                <p>Copyright &copy; 2009 Rensselaer Union.  A project of the <a href="http://sysadmin.union.rpi.edu/">Systems Administration Team</a>.  All rights reserved.</p> 
                <p>Developed in affiliation in with <a href='http://rcos.cs.rpi.edu/'>Rensselaer Center for Open-Source Software</a></p>
            </div> 
            </div> 
        </div> 
    </div> 
        </body>
    </html>
        <?
        }

        function CalendarInit($trigger, $formfield, $labelfield, $format = "%y-%m-%d") {
            $text = <<<CALENDAR
<script type='text/javascript'>
Calendar.setup({
    inputField : "$formfield",
    trigger    : "$trigger",
    fdow       : 0, // sunday is the first day of the week, not monday
    onSelect   : function() {
        // save the new value in a hidden field
        var date = this.selection.get();
        
        // show the value to the user so they can read it
        date = Calendar.intToDate(date);
        
        datevar = Calendar.printDate(date, "$format");
        readable = Calendar.printDate(date, "%o/%e/%Y");

        $("$labelfield").innerHTML = readable;
        $("$formfield").value = datevar;
        
        this.hide();
    }
});
</script>
CALENDAR;
            return $text;
        }
    }

?>
